package com.xbj.mvc;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbj.mvc.action.Action;
import com.xbj.mvc.form.ActionForm;
import com.xbj.mvc.utils.FullBean;

public class ActionServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1575639135607588017L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		super.doGet(req, resp);
		String sign = req.getParameter("sign");
		ActionForm form = FullBean.full(req);
		Map<String,String> mapping = new ActionMapping().getMap();
		Action action = null;
		try {
			Class clazz = Class.forName(mapping.get(sign));
			action = (Action)clazz.newInstance();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} 
		
		String message = action.execute(form);
		System.out.println(message);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		super.doPost(req, resp);
		this.doGet(req, resp); 
	}
	
	

	
}
